/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.shared.model;

import java.lang.reflect.Modifier;

import javax.xml.bind.annotation.XmlType;

import com.google.common.annotations.GwtCompatible;
import com.google.gson.annotations.Expose;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.Type;

/**
 * Implementation of {@link FieldDoc}
 *
 * @author Chad Retz
 */
@XmlType(name = "field")
@GwtCompatible(serializable = true)
@SuppressWarnings("serial")
public class FieldDocImpl extends MemberDocImpl implements FieldDoc {

    //exposed fields
    
    @Expose
    private Object constantValue;
    
    @Expose
    private String constantValueExpression;
    
    @Expose
    private SerialFieldTagImpl[] serialFieldTags;
    
    @Expose
    private String type;
    
    //non-exposed fields
    
    private transient Type typeLoaded;
    
    //FieldDoc impl
    
    @Override
    public Object constantValue() {
        return constantValue;
    }
    
    @Override
    public String constantValueExpression() {
        return constantValueExpression;
    }
    
    @Override
    public boolean isTransient() {
        return Modifier.isTransient(modifierSpecifier());
    }
    
    @Override
    public boolean isVolatile() {
        return Modifier.isVolatile(modifierSpecifier());
    }
    
    @Override
    public SerialFieldTagImpl[] serialFieldTags() {
        return serialFieldTags;
    }
    
    @Override
    public Type type() {
        if (typeLoaded == null) {
            typeLoaded = getContext().getType(type);
        }
        return typeLoaded;
    }
    
    //other accessors
    
    public void setConstantValue(Object constantValue) {
        this.constantValue = constantValue;
    }
    
    public void setConstantValueExpression(String constantValueExpression) {
        this.constantValueExpression = constantValueExpression;
    }
    
    public void setSerialFieldTags(SerialFieldTagImpl[] serialFieldTags) {
        this.serialFieldTags = serialFieldTags;
    }
    
    public String getType() {
        return type;
    }
    
    public void setType(String type) {
        this.type = type;
    }
    
}
